package baseTest;

import java.util.HashMap;

public class copyRandomList {

    public static void main(String[] args) {

    }

    public RandomNode process(RandomNode head){
        HashMap<RandomNode, RandomNode> map = new HashMap<>();

        RandomNode cur = head;
        while (cur != null){
            map.put(cur,new RandomNode(cur.val));
            cur = cur.next;
        }
        cur = head;
        while (cur != null){
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return  map.get(head);
    }
}
